$(function() {
	$("#cover").uploadify({
		buttonText:'选择文件',
		height: 20,
		swf: 'uploadify/uploadify.swf',
		uploader: 'changeCover',
		width: 60,
		fileSizeLimit: '1MB',
		fileTypeExts: '*.gif; *.jpg; *.png',
		onUploadSuccess: uploadSuccess,
		onUploadStart : function(file) 
        {
            $("#cover").uploadify('settings','formData',{'cover':$("input[name='cover_url']").val(),'animeId':$("#id").val()});
        },
        onSWFReady :function()
        {
        	if($("#id").val()=="")
        	{
        		$("#cover").uploadify('disable',true);
        	}
        }
	});
	$("#cv").combobox({
	    url:'cvManage/getCV',
	    valueField:'id',
	    textField:'name',
	    onBeforeLoad:defaultSelect,
	    onSelect:appendCV
	});
	$(".delete_img").live("click",function(){
		ids.remove($(this).parent().find(":input").val());
		$(this).parent().find(":input").val("");
		$(this).parent().replaceWith("");
	});
});
//声优idSet防止多次选择声优重复
var ids = new Set();
//设置声优的默认选项
function defaultSelect()
{
	$.ajax(
		{
			url:'animeCVManage',
			dataType:'json',
			data:'animeId='+$("#id").val(),
			success:function(data, textStatus){
				for(var i in data)
				{
					appendCV(data[i]);
				}
			}
		}	
	);
}
function appendCV(data)
{
	if(!ids.contains(data.id))
	{
		ids.add(data.id);
		$("#cv").parent().append("<span><input type='hidden' name='cv' value='"+
				data.id+"'><span class='label_show'>"+data.name+"</span><a href='javascript:void(0)' class='delete_img'></a></span>");
	}
}
function submitForm(){
    $('#animeEdit').form('submit',{
    	url:'animeManage/saveAnime',
    	onSubmit: function(){
    		return $(this).form('validate');
        },
    	success:function(data){
    		//返回的动漫Id写入页面
    		$("#id").val($.parseJSON(data).id);
    		$.messager.show({  
                msg:'保存成功！',
                timeout:2000,
                showType:'show'  
            });
    		$("#cover").uploadify('disable',false);
    	}
    });
}
function closeForm(){
	opener.animeReload();
    window.close();
}